﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Trangtrai.Controller.Global;
using System.Data.SqlClient;

namespace Trangtrai.CauhinhController
{
    public class FoodController
    {
        public static void InsertFoodSeperate (int foodKind, String foodCode, String foodName, String note)
        {
            if (ConnectionClass.ConnectToDB())
            {
                SqlCommand insertCmd = new SqlCommand("INSERT INTO FOOD (FOOD_NAME, FOOD_CODE, TYPE_ID, NOTE) VALUES ('" + foodName + "','" +
                    foodCode + "'," + foodKind + ",'" + note + "')", ConnectionClass.sqlConn);

                insertCmd.ExecuteNonQuery();
                ConnectionClass.closeConn();
            }
        }

        public static void InsertFoodMix(String food_code, String food_TP_ID, float rate)
        {
            if (ConnectionClass.ConnectToDB())
            {
                SqlCommand insertIntergrate = new SqlCommand("INSERT INTO INTEGRATED_FOOD (INTEGRATED_FOOD_ID, FOOD_TP_ID, RATE) VALUES ("
                        + "(SELECT FOOD_ID FROM FOOD WHERE FOOD_CODE = '" + food_code + "')" + ",(SELECT FOOD_ID FROM FOOD WHERE FOOD_CODE ='" +
                    food_TP_ID + "')," + rate + ")", ConnectionClass.sqlConn);
                insertIntergrate.ExecuteNonQuery();

                ConnectionClass.closeConn();
            }
        }
    }
}